﻿namespace FluentMvc.Test.Models
{
    using Controllers;
    using MvcIntegration;
    using Validators;

    public class User : IModelInitializer<User>
    {
        public string Username { get; set; }
        public string Password { get; set; }
        public bool LicenseAgreements { get; set; }
        public UserProfile Profile { get; set; }

        public void InitializeModel(ModelContext<User> context)
        {
            context.TemplatesFor(user => user.Username)
                .Display("Name of user")
                .UIHint(UIHint.MultilineText);
            context.RulesFor(user => user.Username)
                .Required(c => c.Message("Username is required").StopOnFail())
                .Length(3, 10, c => c.Message("User name length must between 3 and 10"))
                .Remote<HomeController>(controller => controller.UsernameExists);
            context.RulesFor(user => user.Password)
                .Required(c => c.Message("Password is required"));
            context.RulesFor(user => user.LicenseAgreements)
                .CustomValidator(new MustBeTureValidator(), c => c.Message("License agreements must be checked"));
        }
    }
}